<?php
include '../newlib.php';
include '../lib/AppScope.pre.php';

$theUser = $app->theUser;
$program = $_REQUEST["program"];
$position =$_REQUEST["position"];
$invoegen = $_REQUEST["invoegen"];

$stm = $tmpConnection->prepare('select * from programs where id=:id');
$stm->execute(array(':id' => $program));
$rs = $stm->fetch(PDO::FETCH_ASSOC);
$volgorde = explode(";",$rs['volgorde']);
$newVolgorde = array();
if ($position < 0) {
	$newVolgorde[] = $invoegen;
}
foreach ($volgorde as $value) {
	$newVolgorde[] = $value;
	if ($value == $position) {
		$newVolgorde[] = $invoegen;
	}
}
$stm = $tmpConnection->prepare('update programs set volgorde=:volgorde where id=:id');
$stm->execute(array(':volgorde' => implode(";", $newVolgorde),':id' => $program));
header("Location: editprog.php" . "?program=" . $program);

?>